/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.component.schema;

import com.inspur.edp.caf.cef.schema.base.element.impl.DefaultParameter;
import com.inspur.edp.caf.cef.schema.datatype.DataType;
import com.inspur.edp.component.schema.enums.ControlType;
import com.inspur.edp.component.schema.utils.DataTypeConverter;

import java.util.ArrayList;
import java.util.List;

/**
 * @auther zhouyjtr
 * @date 2021年12月31日
 */
public class GspCompParameter extends DefaultParameter {

    private ControlType controlType;
    private Object customControlSource;
    private HelpInfo helpInfo;
    private IGspCompConstraint paramConstraint;
    private final List<EnumItem> enumCollection = new ArrayList<>();
    //    public static final String KIND = "GspCompParameter";
    public static final String KIND = DefaultParameter.KIND;

    public GspCompParameter() {
        this.setKind(GspCompParameter.KIND);
    }

    public ControlType getControlType() {
        return controlType;
    }

    public void setControlType(ControlType controlType) {
        this.controlType = controlType;
    }

    public Object getCustomControlSource() {
        return customControlSource;
    }

    public void setCustomControlSource(Object customControlSource) {
        this.customControlSource = customControlSource;
    }

    public HelpInfo getHelpInfo() {
        return helpInfo;
    }

    public void setHelpInfo(HelpInfo helpInfo) {
        this.helpInfo = helpInfo;
    }

    @Override
    public GspCompParamType getParameterType() {
        return (GspCompParamType) super.getParameterType();
    }

    /**
     * 此方法cdt序列化会调用
     *
     * @param parameterType 内部转化为GspCompParamType
     */
    @Override
    public void setParameterType(DataType parameterType) {
        if (parameterType == null || parameterType instanceof GspCompParamType) {
            this.setParameterType((GspCompParamType) parameterType);
        } else {
            GspCompParamType paramType = DataTypeConverter.getGspCompParamType(parameterType);
            setParameterType(paramType);
        }
    }

    public void setParameterType(GspCompParamType parameterType) {
        super.setParameterType(parameterType);
    }

    public List<EnumItem> getEnumCollection() {
        return enumCollection;
    }


    @Override
    public void setDefaultValue(String defaultValue) {
        if ("".equals(defaultValue)) {
            throw new UnsupportedOperationException();
        }
        super.setDefaultValue(defaultValue);
    }

    public IGspCompConstraint getParamConstraint() {
        return paramConstraint;
    }

    public void setParamConstraint(IGspCompConstraint paramConstraint) {
        this.paramConstraint = paramConstraint;
    }

    @Override
    public String getKind() {
        return KIND;
    }
}
